package br.com.drestranho.escola.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import br.com.drestranho.escola.entity.AvaliacaoItem;

@Stateless
public class AvaliacaoItemDAO {
	@PersistenceContext(unitName="H6Escola")
	private EntityManager em;
	
	public void salvar(AvaliacaoItem bean) {
		em.persist(bean);
	}
	
	public void atualizar(AvaliacaoItem bean) {
		em.merge(bean);
	}
	
	public void remover( AvaliacaoItem bean) {
		em.remove(em.merge(bean));
	}
	
	public AvaliacaoItem getBean(Integer id) {
		AvaliacaoItem bean = em.find(AvaliacaoItem.class, id);
		return bean;
	}
	
	public List<AvaliacaoItem> getBeans(){//Lista 
		CriteriaBuilder cb = em.getCriteriaBuilder();
		CriteriaQuery<AvaliacaoItem> cq = cb.createQuery(AvaliacaoItem.class);
		Root<AvaliacaoItem> from = cq.from(AvaliacaoItem.class);
		CriteriaQuery<AvaliacaoItem> select = cq.select(from);
		List<AvaliacaoItem> AvaliacaoItems = em.createQuery(select).getResultList();
		return AvaliacaoItems;
	}
	
}
